package my.myorm.tool.jdbc;

import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-10-22
 * Time: 10:55:55
 * To change this template use File | Settings | File Templates.
 */
public class MySqlResultSetHandler extends ResultSetHandler{
    private static Field field = null;

    static {
        try {
            field = com.mysql.jdbc.ResultSetMetaData.class.getDeclaredField("fields");
            field.setAccessible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    protected ResultSetField[] getResultSetFields(ResultSet rs) throws Exception {
        ResultSetMetaData metadata=rs.getMetaData();
        com.mysql.jdbc.Field[] fields = (com.mysql.jdbc.Field[]) field.get(metadata);
        ResultSetField[] myfields=new ResultSetField[fields.length];
        for(int i=0;i<fields.length;i++){
            myfields[i]=new ResultSetField();
            myfields[i].setTableName(fields[i].getTableName());
            myfields[i].setOriginalTableName(fields[i].getOriginalTableName());
            myfields[i].setName(fields[i].getName());
            myfields[i].setFullOriginalName(fields[i].getFullOriginalName());
            
       //     System.out.println("TableName:" + fields[i].getTableName());
       //     System.out.println("OriginalTableName:" + fields[i].getOriginalTableName());
       //     System.out.println("Name:" + fields[i].getName());
       //     System.out.println("FullOriginalName:" + fields[i].getFullOriginalName());
        }
        return myfields;
    }
}
